﻿using System;
using System.Collections.Generic;
using System.Text;


using Gx.Dal.Employee;//数据
using Gx.Model.Entity;//实体
using Gx.Common;//通用类
using Gx.Model;
using Gx.Model.Enums;
using Gx.Bll.Shared;

namespace Gx.Bll.Employee
{
    /// <summary>
    /// 
    /// </summary>
    public class E_ClassInfoBll
    {
        public ReturnModel<bool> AddE_ClassInfo(E_ClassInfo model)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                ReturnModel<bool> r = new ReturnModel<bool>()
                {
                    Code = (int)Code.操作失败,
                    Msg = "操作失败",
                    Success = false,
                };
                if (model.ClassName.IsNullOrEmpty())
                {
                    r.Msg = "班次名称不能为空";
                    return r;
                }
                bool res = dal.AddE_ClassInfo(model);
                if (res)
                {
                    new M_LogInfoBll().AddOptionsLog("AddE_ClassInfo", LoginHelper.GetUserId() + "添加一条班次信息", model);
                    r.Code = (int)Code.操作成功;
                    r.Msg = "操作成功";
                    r.Data = true;
                    r.Success = true;
                }
                return r;
            }
        }

        public ReturnModel<bool> DelE_ClassInfo(int Id)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                ReturnModel<bool> r = new ReturnModel<bool>()
                {
                    Code = (int)Code.操作失败,
                    Msg = "操作失败",
                    Success = false,
                };
                bool res = dal.DelE_ClassInfo(Id);
                if (res)
                {
                    new M_LogInfoBll().AddOptionsLog("DelE_ClassInfo", LoginHelper.GetUserId() + "删除一条班次信息", Id);
                    r.Code = (int)Code.操作成功;
                    r.Msg = "操作成功";
                    r.Data = true;
                    r.Success = true;
                }
                return r;
            }
        }

        public ReturnModel<bool> EditE_ClassInfo(E_ClassInfo model)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                ReturnModel<bool> r = new ReturnModel<bool>()
                {
                    Code = (int)Code.操作失败,
                    Msg = "操作失败",
                    Success = false,
                };
                if (model.ClassName.IsNullOrEmpty())
                {
                    r.Msg = "班次名称不能为空";
                    return r;
                }
                bool res = dal.EditE_ClassInfo(model);
                if (res)
                {
                    new M_LogInfoBll().AddOptionsLog("EditE_ClassInfo", LoginHelper.GetUserId() + "编辑一条班次信息", model);
                    r.Code = (int)Code.操作成功;
                    r.Msg = "操作成功";
                    r.Data = true;
                    r.Success = true;
                }
                return r;
            }
        }

        public List<E_ClassInfo> GetE_ClassInfoList()
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                return dal.GetE_ClassInfoList(string.Empty);
            }
        }

        private List<E_ClassInfo> GetE_ClassInfoList(string strWhere)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                return dal.GetE_ClassInfoList(strWhere);
            }
        }

        public List<E_ClassInfo> GetE_ClassInfoList(int pageIndex, int pageSize, out int totalCount)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                int PageIndex = (pageIndex - 1) * pageSize + 1;
                int PageSize = pageIndex * pageSize;
                StringBuilder strWhere = new StringBuilder();
                strWhere.Append(" AND Status=0");
                return dal.GetE_ClassInfoList(strWhere.ToString(), PageIndex, PageSize, out totalCount);
            }
        }

        public E_ClassInfo GetE_ClassInfoModel(int id)
        {
            using (E_ClassInfoDal dal = new E_ClassInfoDal())
            {
                return dal.GetE_ClassInfoModel(id);
            }
        }
    }
}
